package com.springMVCStudy.path;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/path")
@ResponseBody
public class PathController {

    // 动态路径的配置，如path/账号/密码
    /*
    需要@PathVariable指定为动态路径的参数，不然会识别成Param的参数
    指定路径的{key}要和方法中形参名一致，不一致要用@PathVariable的value属性设成一致的。
    另外@PathVariable和@RequestParam一样也能设置required等属性
     */
    @RequestMapping("/{username}/{password}")
    public String login(@PathVariable(value = "username") String account, @PathVariable String password) {
        System.out.println("account = " + account + ", password = " + password);
        return "account = " + account + ", password = " + password;
    }
}
